<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Userinfo extends Frontend
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    // 显示表单
    public function index()
    {
        return $this->fetch();
    }

    // 处理表单提交
    public function submit()
    {
        if ($this->request->isPost()) {
            // 获取表单数据
            $data = $this->request->post();

            if(empty($data['job_number'])){
                $this->error('请填写工号');
            }
            if(empty($data['item'])){
                $this->error('请填写物品');
            }
            if(empty($data['name'])){
                $this->error('请填写姓名');
            }
            if(empty($data['phone'])){
                $this->error('请填写电话');
            }
            if(strlen($data['phone']) != 11){
                $this->error('手机号格式错误');
            }

            // 这里可以添加数据处理逻辑，比如保存到数据库
            // 示例：打印表单数据
            //print_r($data);
            $data['createtime'] = time();
            $data['updatetime'] = time();
            Db::table('fa_submit')->insert($data);
            // 返回成功信息
            $this->success('表单提交成功');
        } else {
            $this->error('非法请求');
        }
    }
}